package pages

import (
	"net/http"
	"note-go/models"
	"note-go/pkg/database"
	"note-go/session"

	"github.com/gin-gonic/gin"
)

func UsersSettingsProfilePage(c *gin.Context) {
	sessionID, _ := c.Cookie("session_id")
	username, _ := session.GetSession(sessionID)
	var user models.User
	result := database.DB.Where("username = ?", username).
		First(&user)

	if result.Error != nil {
		c.JSON(http.StatusOK, gin.H{
			"code":    400,
			"status":  "fail",
			"message": "登录失败，请确认用户名和密码是否正确",
		})
		c.Abort()
		return
	}
	c.HTML(http.StatusOK, "usersSettingsProfile.html", gin.H{
		"title":         "Note Go",
		"selected_item": "users",
		"username":      username,
		"name":          user.Name,
		"is_login":      true,
	})
}
